// 拓扑排序可以排非连通图？！

#include <bits/stdc++.h>
using namespace std;
const int N = 300'000 + 10;
// dp[i][alpha] 表示在字符串前i个字符组成的图中
// alpha这个字符的最大数量
int dp[N][26];
char s[N];
int indeg[N];
vector<int> adj[N];
int m, n;
int main() {
  cin >> n >> m >> s + 1;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    indeg[v]++;
    adj[u].push_back(v);
  }
  queue<int> q;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (indeg[i] == 0) {
      q.push(i);
      dp[i][s[i] - 'a'] = 1;
    }
  }
  while (q.size()) {
    int u = q.front();
    q.pop();
    cnt++;
    for (auto v : adj[u]) {
      for (int j = 0; j < 26; ++j) {
        dp[v][j] = max(dp[v][j], dp[u][j] + (s[v] - 'a' == j));
      }

      indeg[v]--;
      if (indeg[v] == 0) q.push(v);
    }
  }

  int ans = -1;
  // 因为这道题特殊所以找答案需要找遍dp数组
  if (cnt == n) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j < 26; ++j) {
        ans = max(ans, dp[i][j]);
      }
    }
  }

  cout << ans << endl;
}
